$(document).ready(function() {
    function _T($key) {       
        if (typeof(alohacart_lang) != 'undefined') {
            if (typeof(alohacart_lang[$key]) != 'undefined') {
                return alohacart_lang[$key];
            }
        }
        return $key;
    }
    
	// Add product to cart via AJAX request
    $("a.alohacart_add_product_link").click(function() {
       $.post('./?page=alohacart_ajax',
            {
                act: "add_product",
                id_product: $(this).attr('id_product'),
                article: $(this).attr('article'),
                titre: $(this).attr('titre'),
                price: $(this).attr('price'),
                img_file: $(this).attr('img_file'),
                link: $(this).attr('link')
            },
            function(data){
               if (data) { //alert(data);
                    var cart_quantity = $.evalJSON(data).cart_quantity;
                    var cart_price = $.evalJSON(data).cart_price;
                    $(".alohacart_quantity_display").text(cart_quantity);
                    $(".alohacart_price_display").text(cart_price);
                    alert(_T('product_added'));
               }		 
            });
       
	});
    
    // Clear cart via AJAX request
    $("a.alohacart_clear_cart_link").click(function() {
       $.post('./?page=alohacart_ajax',
            {
                act: "clear_cart"
            },
            function(data){
               if (data) { //alert(data);
                    if (data == 'DeleteOK') { 
                        $(".alohacart_quantity_display").text('0');
                        $(".alohacart_price_display").text('0');
                        alert(_T('cart_empty'));
                    }
               }		 
            });
	});
    
});